package bg.code.commons.builder.project;

import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.util.xmlb.XmlSerializerUtil;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 郑兴泉 956607644@qq.com
 * @data 2020/3/18
 * 描述：
 */
@State(
        name = "BgCodeGenerate",
        storages = {@Storage("BgCodeGenerate.xml")}
)
public class ToolConfigurationData implements PersistentStateComponent<ToolConfigurationData> {

    private String templatePath;
    private String userMail;
    private String userName;
    private List<String> templateNames = new ArrayList();

    public ToolConfigurationData() {
    }

    @Nullable
    public static ToolConfigurationData getInstance() {
        return ServiceManager.getService(ToolConfigurationData.class);
    }

    @Nullable
    @Override
    public ToolConfigurationData getState() {
        return this;
    }

    @Override
    public void loadState(ToolConfigurationData toolConfigurationData) {
        if (toolConfigurationData == null) {
            throw new RuntimeException("参数为空");
        }
        XmlSerializerUtil.copyBean(toolConfigurationData, this);
    }

    public String getTemplatePath() {
        return templatePath;
    }

    public void setTemplatePath(String templatePath) {
        this.templatePath = templatePath;
    }

    public String getUserMail() {
        return userMail;
    }

    public void setUserMail(String userMail) {
        this.userMail = userMail;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public List<String> getTemplateNames() {
        return templateNames;
    }

    public void setTemplateNames(List<String> templateNames) {
        this.templateNames = templateNames;
    }
}
